function getBase64Image(img) {
    var canvas = document.createElement("canvas");
    canvas.width = img.width;
    canvas.height = img.height;
    var ctx = canvas.getContext("2d");
    ctx.drawImage(img, 0, 0, img.width, img.height);
    var ext = img.src.substring(img.src.lastIndexOf(".") + 1).toLowerCase();
    var dataURL = canvas.toDataURL('image/jpeg');
    return dataURL;
}

//接受参数为触发了onchange事件后的input[type=file]的DOM结构
function getExif(file,callBack) { 
    // 通过FormData将文件转成二进制数据
    var fileReader = new FileReader();
    if (!file.files) {
        return
    };
    fileReader.readAsDataURL(file.files[0]);
    fileReader.onload = function (e) {
        if (FileReader.DONE == fileReader.readyState) {
            var img = new Image();
            img.onload = function () {
                //这里读取图片的头部信息  START
                EXIF.getData(img, function () {
                    console.log("图片方向",img.exifdata.Orientation);
                    console.log("图片拍摄设备",EXIF.getTag(img, "Make"));
                    var imgOrien = img.exifdata.Orientation;
                    var needRotation;
                    switch(imgOrien){
                        case 3: needRotation = 180;break;
                        case 6: needRotation = 90;break;
                        case 8: needRotation = -90;break;
                        default : needRotation = 0;
                    }
                    var result = {
                        imgOrien:imgOrien,
                        needRotation:needRotation
                    }
                    typeof callBack == "function" && callBack(result);
                    return result;
                });
            }
            img.src = this.result; //是Base64的data url数据
        }

    }
}